import { createRouter, createWebHashHistory } from 'vue-router'
import Common from '@/wujie/micros/common.vue'
import { getToken } from '@common'
export const microViews = {
  common: Common
}

const defaultRouterList = [
  {
    path: '/',
    name: 'layout',
    component: () => import('@/layout/index.vue')
    // children: microsRouterList
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue')
  }
]

export const allRoutes = [...defaultRouterList]

const router = createRouter({
  history: createWebHashHistory(),
  routes: defaultRouterList,
  scrollBehavior() {
    return {
      el: '#app',
      top: 0,
      behavior: 'smooth'
    }
  }
})

router.beforeEach((to, from, next) => {
  if (to.name !== 'login' && !getToken()) {
    next({ name: 'login' })
  } else {
    next()
  }
})

export default router
